<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    // 解决多个异步函数 顺序执行的问题
    function fun1 () {
      setTimeout(() => {
        console.log('定时器第一个4s');
        iterator.next();//调用fun2()
      }, 4000);
    }
    function fun2 () {
      setTimeout(() => {
        console.log('定时器第一个3s');
        iterator.next();//调用fun3()
      }, 3000);
    }
    function fun3 () {
      setTimeout(() => {
        console.log('定时器第一个2s');
      }, 2000);
    }

    function* fun () {
      yield fun1();
      yield fun2();
      yield fun3();
    }
    let iterator = fun();
    console.log(iterator);
    iterator.next();//调用fun1()

  </script>
</body>

</html>